Skip to content

万宝锐旗直招-ethan-frontend #1841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Weikaixiong
Copy link

No description provided.

@Weikaixiong Weikaixiong changed the title 万宝锐旗外包-ethan-frontend ethan-frontend Apr 19, 2023
@Weikaixiong Weikaixiong force-pushed the master branch 2 times, most recently from ae28049 to 7a3c9e9 Compare April 19, 2023 10:47
@Weikaixiong Weikaixiong changed the title ethan-frontend 万宝锐旗直招-ethan-frontend Apr 20, 2023
}
}
onMouseLeave={()=>{
setAuto(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解这个地方可能设计的有些问题,autoplay 本质上是决定轮播图是不是自动播放的,如果这样设计的话,即使我设置了 false,点击之后又变成自动播放了

@YuHanLi777
Copy link
Collaborator

可以的话补充一些测试代码吧

}

const Carousel: FC<CarouselProps> = ({ items, delay = 3000, autoPlay = true}) => {
const [active, setActive] = useState<number>(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用传。从初始值会自动推导


const Carousel: FC<CarouselProps> = ({ items, delay = 3000, autoPlay = true}) => {
const [active, setActive] = useState<number>(0)
const [auto,setAuto] = useState<boolean>(autoPlay)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

const [auto,setAuto] = useState<boolean>(autoPlay)

useEffect(() => {
if (active >= items.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种边界情况是在防止什么 case, items 的变动吗,我理解如果是这样不应该是这样来处理

return
}
const timer = setTimeout(() => setActive((active + 1) % items.length), delay)
if(!auto){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里用 auto 判断属于为了交互强行写逻辑了,auto 不纯粹且和交互严重耦合

}}
>
<div className="text-content" style={{ color: item.color }}>
<h2 className="title">{item.title?.join('\r\n')}</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item.title 不存在还要展示 这个 h2 吗

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的 应该{item.title &&

{item.title?.join('\r\n')}

}

{items.map((item, idx) => (
<li
key={item.id}
className={`${idx === active ? 'indicator active' : 'indicator'}`}
Copy link
Collaborator

@YuHanLi777 YuHanLi777 Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indicator ${idx === active ? 'active' : '‘}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种模板字符串的话 indicator 后面会多一个空格

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indicator${idx === active ? ' active' : '‘}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants